package work.xiaohong.jijin.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author : xiaohong
 * @date : 2021/4/9 11:50
 */
public class TimeUtil {


    /**
     * 获得当前时间多少天后的日期
     * @param days
     * @return
     */
    public static String getDay(Integer days){
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, days);
        Date result = (Date) calendar.getTime();
        return format.format(result);
    }

    /**
     * 是否在指定的天数内
     * @param day
     * @param dayNumber
     * @return
     */
    public static Boolean isInDay(String day, Integer dayNumber){
        if (dayNumber >= 0){
            for (int i = 0; i < dayNumber; i++) {
                String gday = getDay(i);
                if (gday.equals(day)){
                    return true;
                }
            }
        }else {
            for (int i = dayNumber; i < 0; i++) {
                String gday = getDay(i);
                if (gday.equals(day)){
                    return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        String day = "2021-03-30";
        System.out.println(isInDay(day,-10));
    }

}
